package com.itboye.zhujia.login;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.itboye.zhujia.R;
import com.itboye.zhujia.base.BaseActivity;
import com.itboye.zhujia.network.HttpRequest;
import com.itboye.zhujia.util.DebugLog;
import com.itboye.zhujia.util.T;
import com.itboye.zhujia.volley.CodeErrorException;
import com.itboye.zhujia.volley.MyJsonRequest;
import com.itboye.zhujia.volley.XErrorListener;
import com.itboye.zhujia.volley.XRequestListener;

/**
 * 忘记密码3（重新输入密码）
 * 
 */
public class PasswordActivityThree extends BaseActivity implements
		OnClickListener {
	ImageView close_icon;// 返回图片
	TextView add_shap_title_tv;// 标题
	EditText pass_three_num;// 密码
	TextView pass_three_ok;// 完成

	private Intent intent;

	private String phone;// 接上页面传来的手机号
	private String yzm;// 接上页面传来的验证码

	@Override
	public int initView() {
		return 0;
	}

	@Override
	public void onMyCreate() {
		setContentView(R.layout.activity_password_three);

		add_shap_title_tv.setText("重置密码");

		intent = super.getIntent();
		phone = intent.getStringExtra("phone");
		yzm = intent.getStringExtra("yam");

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();

			break;
		case R.id.pass_three_ok:// 完成
			changepassword();
			break;

		default:
			break;
		}

	}

	/**
	 * 修改密码
	 */
	private void changepassword() {

		if (pass_three_num.getText().toString() == null) {
			T.showShort(this, "请请输入密码");
			return;
		}
		MyJsonRequest<String> request = new MyJsonRequest.Builder<String>()
				.apiVer("100").typeKey("BY_User_findPswByMobile")
				.param("mobile", phone)
				.param("code", yzm)
				.param("psw", pass_three_num.getText().toString())
				.requestListener(new XRequestListener<String>() {

					@Override
					public void onResponse(String response) {
						DebugLog.v("result", response.toString());
						T.showShort(PasswordActivityThree.this, response);

						// login();

						finish();

					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {
						if (exception instanceof CodeErrorException) {
							T.showShort(PasswordActivityThree.this, msg);
						} else {
							T.showShort(PasswordActivityThree.this, exception.toString());
						}

					}
				}).build();
		HttpRequest.getDefaultRequestQueue().add(request);
	}

}
